// MailMan.cpp: implementation of the CMailMan class.
//
//////////////////////////////////////////////////////////////////////

#include "MailMan.h"
#include <iostream>


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMailMan::CMailMan()
:m_SockHandler()
,m_SmtpSock(m_SockHandler)
{

}

CMailMan::~CMailMan()
{

}

void CMailMan::SetSmtpHost(const std::string& host)
{
	m_SmtpSock.SetSmtpHost(host);
}

void CMailMan::SetSmtpPort(unsigned int port)
{
	m_SmtpSock.SetSmtpPort(port);
}

void CMailMan::SetSmtpUsername(const std::string& usr)
{
	m_SmtpSock.SetSmtpUsername(usr);
}

void CMailMan::SetSmtpPassword(const std::string& pwd)
{
	m_SmtpSock.SetSmtpPassword(pwd);
}

void CMailMan::EnableSmtpSSL(bool enable/* = TRUE*/)
{
	m_SmtpSock.EnableSSL(enable);
}


bool CMailMan::SendMail(CEmail &mail)
{	
	if( m_SmtpSock.IsConnected() )
		m_SmtpSock.Close();

	if( !m_SmtpSock.Connect() )
		return false;

	m_SmtpSock.SendMail(&mail);

	m_SockHandler.Add(&m_SmtpSock);
	while (!m_SmtpSock.CloseAndDelete())
	{
		m_SockHandler.Select();
	}

	return m_SmtpSock.IsMailSent();
}
